package com.oak.interviewdemo.sys.controller;

import com.oak.interviewdemo.sys.service.IUserService;
import com.oak.interviewdemo.utils.page.PageR;
import com.oak.interviewdemo.utils.page.PageStatus;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * LoginController
 *
 * @Author: guoxy
 * @Date: 2020/5/14 23:47
 * @Description:
 * @Version: 1.0
 */
@Slf4j
@Controller
@Api(value = "/login", tags = "登录管理接口")
public class LoginController {

    @Autowired
    private IUserService userService;

    @ApiOperation(value = "登录管理接口", notes = "登录管理接口(-)")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "username", value = "用户名", required = false, dataType = "String", defaultValue = "admin"),
            @ApiImplicitParam(paramType = "query", name = "password", value = "密码", required = false, dataType = "String", defaultValue = "123456")
    })
    @RequestMapping("/checkLogin")
    @ResponseBody
    public PageR login(String username, String password) {
        log.info("username:{},password:{}", username, password);
        boolean isLogin = userService.checkLogin(username, password);
        if (!isLogin) {
            return PageR.putCodeMsg(PageStatus.LOGIN_ERROR);
        }
        return PageR.putCodeMsg(PageStatus.LOGIN_SUCCESS);
    }

    @GetMapping("/login")
    public String login() {
        return "login/login";
    }

    @GetMapping("/403")
    public PageR noauth()  {
        return new PageR("403","没有权限，请联系管理员授权");
    }

}
